package com.financial.token.contoller;

import com.financial.token.service.PlatformTokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.io.BufferedInputStream;

/**
 * 功能描述
 *
 * @author WANGNING
 * @date Create in 2019/10/28 16:23
 * @email wyn20140226@aliyun.com
 * @des 获取调用金融中心accesstoken
 * @tar 调用方 各个调用金融中心的服务
 */
@RestController
@RequestMapping("/authorityConfig")
public class PlatformTokenContoller {

    @Autowired
    private PlatformTokenService platformTokenService;

    /**
     * @param request
     * @return String
     */

    @RequestMapping(value = "/getAccessToken")
    @ResponseBody
    public String getAccessToken(HttpServletRequest request) {
        StringBuffer strJson = new StringBuffer();
        try {
            BufferedInputStream in = new BufferedInputStream(request.getInputStream());
            int i;
            char c;
            while ((i = in.read()) != -1) {
                c = (char) i;
                strJson.append(c);
            }

        } catch (Exception ex) {
            ex.printStackTrace();
        }
        String string = strJson.toString();
        return platformTokenService.getAccessToken(string);
    }

}
